
layui.use(['layer'], function () {

    var $ = layui.jquery,
        layer = layui.layer;
    var browser = getCookie('browser'); //判断 PC 还是 mobile
    console.log(browser)
    // 用户登录
    $("#login").click(function () {
        var username = $("#username").val();
        var password = $("#password").val();
        if (!username) {
            myLayer(browser, "请输入账号！")
            return false
        }
        if (!password) {
            myLayer(browser, "请输入密码！")
            return false
        }
        window.location.href = 'index.html?from=' + 'login';
    })
    // 密码切换
    $(".input-item i.fa").click(function () {
        var show = $(this).attr("data-show"); // 0 隐藏  1显示
        if (show == "0") {
            $(this).attr("data-show", "1")
            $(this).removeClass("fa-eye-slash")
            $(this).addClass("fa-eye")
            $(this).siblings("input").attr("type", "text")
        } else {
            $(this).attr("data-show", "0")
            $(this).removeClass("fa-eye")
            $(this).addClass("fa-eye-slash")
            $(this).siblings("input").attr("type", "password")
        }
    })
    // 用户注册
    $("#register").click(function () {
        // myLayer(browser, "搭建中")
        // return false
        window.location.href = 'register.html?from=' + 'login';
    })

    // 需求说明 当前页
    var word = `<div style="padding: 20px; line-height: 22px;">
        <h1>2020-07-07</h1>
        <p>1、允许手机号 邮箱 账号校验登录</p>
        <p>2、添加管理员账号：admin Aa123456</p>
        <p>3、管理员账号可以登录添加用户</p>
    </div>`;
    documentText(word)


    // 遍历数据测试
    var train = [{
        "TRAIN_ID": "BJ1",
        "TRACK_LIST": [
            {
                "TRACK_ID": "H101",
                "TRAIN_TYPE": "A",
                "TRAIN_STATE": "A",
                "I_FE_FLAG": "0",
                "TRAIN_INFO": {
                    "TRAIN_NAME": "BJ1货车列车1",
                    "ARRIV_NUM": "ARRIV001",
                    "ARRIV_DATE": "20200707",
                    "COACH_COUNT": "30",
                    "TRAIN_PRICE": "999122"
                }
            },
            {
                "TRACK_ID": "H102",
                "TRAIN_TYPE": "B",
                "TRAIN_STATE": "B",
                "I_FE_FLAG": "0",
                "TRAIN_INFO": {
                    "TRAIN_NAME": "BJ1货车列车2",
                    "ARRIV_NUM": "ARRIV001",
                    "ARRIV_DATE": "20200707",
                    "COACH_COUNT": "40",
                    "TRAIN_PRICE": "999122"
                }
            },
        ]
    },
    {
        "TRAIN_ID": "BJ2",
        "TRACK_LIST": [
            {
                "TRACK_ID": "H201",
                "TRAIN_TYPE": "A",
                "TRAIN_STATE": "C",
                "I_FE_FLAG": "1",
                "TRAIN_INFO": {
                    "TRAIN_NAME": "BJ2货车列车1",
                    "ARRIV_NUM": "ARRIV001",
                    "ARRIV_DATE": "20200707",
                    "COACH_COUNT": "30",
                    "TRAIN_PRICE": "999122"
                }
            }
        ]
    },
    {
        "TRAIN_ID": "##1",
        "TRACK_LIST": [
            {
                "TRACK_ID": "H101",
                "TRAIN_TYPE": "A",
                "TRAIN_STATE": "A",
                "I_FE_FLAG": "0",
                "TRAIN_INFO": {
                    "TRAIN_NAME": "BJ1货车列车1",
                    "ARRIV_NUM": "ARRIV001",
                    "ARRIV_DATE": "20200707",
                    "COACH_COUNT": "30",
                    "TRAIN_PRICE": "999122"
                }
            },
            {
                "TRACK_ID": "H101",
                "TRAIN_TYPE": "A",
                "TRAIN_STATE": "A",
                "I_FE_FLAG": "0",
                "TRAIN_INFO": {
                    "TRAIN_NAME": "BJ1货车列车1",
                    "ARRIV_NUM": "ARRIV001",
                    "ARRIV_DATE": "20200707",
                    "COACH_COUNT": "30",
                    "TRAIN_PRICE": "999122"
                }
            },
            {
                "TRACK_ID": "H101",
                "TRAIN_TYPE": "B",
                "TRAIN_STATE": "A",
                "I_FE_FLAG": "0",
                "TRAIN_INFO": {
                    "TRAIN_NAME": "BJ1货车列车1",
                    "ARRIV_NUM": "ARRIV001",
                    "ARRIV_DATE": "20200707",
                    "COACH_COUNT": "30",
                    "TRAIN_PRICE": "999122"
                }
            }
        ]
    }];
    var ul = $('<div></div>')
    $.each(train, function (item, val) {
        // var li = document.createElement('li')
        var li = $('<div></div>')
        // $(li).text(item)
        $(ul).append(li)
        // console.log(item, val)
        $.each(val.TRACK_LIST, function (i, v) {
            // console.log(i, v)
            var img = $('<img />')
            if (v.TRAIN_TYPE == "A") {
                // $(img).attr("src", "...A")
            } else {
                // $(img).attr("src", "...B")
            }
            $(li).append(img)
        })
    })
    $("body").append(ul)
});